<?php
namespace Web\Controller;
use Think\Controller;
use Web\Logic\SystemLogic;
class WorkOrderController extends BaseController {



    public function ahuList(){

        //获取提交隐含域
        $subs = $_REQUEST['sub'];

        if($subs){
           $phone = $_REQUEST['phone'];
           $start = ($_REQUEST['start_time']);
           $end = ($_REQUEST['end_time']);

           if($phone !=""){
               $where['e.username'] =  $phone;
           }

           if($start !=""){
               $where["DATE_FORMAT(FROM_UNIXTIME(ahu.create_time),'%Y-%m-%d')"] =  array("egt",$start);
           }
           if($end !=""){
               $where["(DATE_FORMAT(FROM_UNIXTIME(ahu.create_time),'%Y-%m-%d'))"] =  array("elt",$end);
           }

           $list = M('employee_inspection_ahu')
           ->alias('ahu')
           ->join(C('DB_PREFIX').'e_employee e ON ahu.phone =e.mac')
           ->field("ahu.*,e.username,e.phone as tel_phone")
           ->order('ahu.create_time asc')
           ->where($where)->select();

           //for($i =0 ; $i <count($list);$i++){
           //     $list[$i]['images'] = $this->getImage($list[$i]['task_id']);
           //}
           //echo M('employee_inspection_ahu')->getLastSql();
           $this->assign('start_time', $_REQUEST['start_time']);
           $this->assign('end_time', $_REQUEST['end_time']);
           $this->assign('phone', $phone);
           $this->assign('list', $list);

        }
         $this->assign('employee', $this->getEmployeeList());
        $this->display();


    }

    public function ahuDetail($id){
           $where['id'] = $id;
           $list = M('employee_inspection_ahu')
           ->alias('ahu')
           ->join(C('DB_PREFIX').'e_employee e ON ahu.phone =e.mac')
           ->field("ahu.*,e.username")
           ->where($where)->find();

           if($list){

           }
           //echo M('employee_inspection_ahu')->getLastSql();
           $this->assign('start_time', $_REQUEST['start_time']);
           $this->assign('end_time', $_REQUEST['end_time']);
           $this->assign('phone', $phone);
           $this->assign('list', $list);


        $this->display();


    }

    public function images($task_id)
    {
            $where['task_id'] = $task_id;
            $list =   M('e_images')->where($where)->select();
             $this->assign('list', $list);


        $this->display();
    }

    public function roomList(){

        //获取提交隐含域
        $subs = $_REQUEST['sub'];

        if($subs){
           $phone = $_REQUEST['phone'];
           $start = ($_REQUEST['start_time']);
           $end = ($_REQUEST['end_time']);

           if($phone !=""){
               $where['e.username'] =  $phone;
           }
           if($start !=""){
               $where["(DATE_FORMAT(FROM_UNIXTIME(ahu.create_time),'%Y-%m-%d'))"] =  array("egt",$start);
           }
           if($end !=""){
               $where["DATE_FORMAT(FROM_UNIXTIME(ahu.create_time),'%Y-%m-%d')"] =  array("elt",$end);
           }

           $list = M('employee_inspection_basic')
           ->alias('ahu')
           ->join(C('DB_PREFIX').'e_employee e ON ahu.phone =e.mac')
           ->field("ahu.*,e.username,e.phone as tel_phone")
           ->order('ahu.create_time asc')
           ->where($where)->select();
           //echo M('employee_inspection_basic')->getLastSql();

           $this->assign('start_time', $_REQUEST['start_time']);
           $this->assign('end_time', $_REQUEST['end_time']);
           $this->assign('phone', $phone);
           $this->assign('list', $list);

        }
         $this->assign('employee', $this->getEmployeeList());
        $this->display();


    }

     /**
    * 取得工作人员
    *
    */
    function getEmployeeList(){
        $list = M('e_employee')->order('userid asc')->field('phone,username')->select();
        return $list;
    }

    /**
    * 取得工作人员
    *
    */
    function getEmployee(){
        $list = M('e_employee')->order('userid asc')->field('phone,username')->select();
        $this->ajaxReturn($list,'json');
    }



}